package com.mojito.learn.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mojito.learn.business.pojo.User;
import com.mojito.learn.business.mapper.UserMapper;
import com.mojito.learn.business.service.UserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author liufq
 * @date 2021/12/23 下午3:40
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private static final String[] telFirst = "134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153".split(",");
    private static final String firstName = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏加封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍却璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱晋楚阎法汝鄢涂钦段干百里东郭南门呼延归海羊舌微生岳帅缑亢况后有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福百家姓续";
    private static final String girl = "秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽 ";
    private static final String boy = "伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘";
    private static final String[] avatars = {
            "https://www.baidu.com/link?url=V3ANLb8nBfru8m5WHq8uJp9afGWTJNphjhJFMI-45WPrtaFIE-dX9ToADj-VIjVMWviJ44xnrl-CU4rqEZ6Ct7S-r8iY9RCKQo8M1J-l8KXHIAZ-IaeXpjEE_JqXE_pOejflXPCjPJpCwnO7uyq0J1DixKzbm669AeXEcH8YahbKNp00ZuFp7etdGQ0i9X_k1oXuMglGqo9NuNboi3KGS26bnnF6rZFztwkkDNYlhX7fIWcjs8MJpKStuereoqw_zJbP0aCK0C4WTmtwplRyt0d00mXQZLQpOFOH7nvsps-g39QRELkm3rbUL8cbSt63y6V4r2ByF7IMVB_PO6CGhoFmqnt12T-EzVmYIQNo_GUau0d0GamO5dkayAgyQvtNFF-w4O52sOz4K2O34S3MLFRNjnSZENz-lY1hTqsUjqJAclwUlwficPlrrzNSWzzGDKlka_JXHjZGrPwWCHbVhdrMkmUTPwdwQmnQRBaxXnvk_SkcXF-LrMsL9vDsoIAAAAJ2nH_MJxqK0EcyS2vNlSIpzAU9bzTLLUE0KuWkieAc1Wm70DPMtm9XhcfmOQGpe6W0kwkMCnMioQouhzOKbUIVvmoZ7097V9AOPst3T22IpHH72k3odu-Zqzv8pPL3EbCZ-1G9Xkei4UdlEv3cVn5zrQxP5knaj3Ru_Q6RQNK&wd=&eqid=bc2385c300045f94000000046221d2ee",
            "https://www.baidu.com/link?url=WhHMif_2S-3aiQuzoBWa9E27gSYTB1-mwqsjAYi6DiGdqrNLvMozqynjM02K88XvIDrdmvolZU3PwsNADsyc9r0dZMzznmnhSNUIlLP9HtFSppBkuqho9dE13MIkl9nst-2M2twcPsUosbjAo591ZgpwvtIZCnuzQPDqO8ircRA1LTsRtyK_CvGrXDokvJe5CH6lkn-LdY0jmzp2mEEhYJ8JIieV6b_gjxTtmgKey1f4hBifuvXZ9JjTW6ZJwieez_L78luESfD-F7EPnyZ07rECmaYqaPC2Z9amo8XdaUf9b2lKjvXu_VFg71K-rAQRu2Oxme0YHvrMOYdbWbjmC777Inidp5OmaEkB7B6dyb59T2ZbxWLXbcQ7PPihpSp4k-6cQB0EInrioo-vbg-jBGoykxr8ny_252V-7rGiQX9qVtVuTWWCGxYpIUJLmC7_S5MROe16SveXtHFSFT56VeRhbPHugv67VHF3LM5XDy_tmo_FMFIS0rW0y-V0UaFkcsuw5cO34UcWi8HIXQaXbjA6nqMNuASeCuxsplJ72wVp5yxvgFHXn2wS1f_xvqanLPXwb2WXW8PDxzTEcHRdenYTMFtZJ6rGVLNhT8FxzJ15Wf0kuQoa56V2oGPhNzOGb4OTblNl3MNkyt2rO0cEQfiO6ZYGOEGc5k1sJFWHZiy&wd=&eqid=bc2385c300045f94000000046221d2ee",
            "https://www.baidu.com/link?url=Fn27E3PmFwecY4OfD6h29_77LW6Uw1G2MECnE39d1MahLIeHjDAa_h4wCmhVMZypdzcKftlI3umwYrqkLn0cbbRW1wIQYXWDpD5q3rfMxA2MEfOcFYttPbxnKjvC4IjM4zqjt2xBu3te1j9l8SlBHi-Ce5anlhuK4xPW3myz9sDvV16hnw4U1fmz1hXDvnuhLYNF7a_RVrN0DP83BPadxXCWR13-v8i8xBbef4Mcr_005swemYYWyLEMl5MU3FlSfIucPwoOYMg1q3eLkE1IQK5uMXn-umTIhdkrrmBpmUWCy47U5quo6Tc9vDXlsPfCQXpMRImTVfqh8Lweu5dV7UGWD8J-z5Hu7tL-J8uznwth5fJU7nacZV4INV71i4y8M6BzstB_BI1XvyvP-74S4SDllUGITfRBBs4XRwN2zbp2qqb1eYieZUV0wMfDqtDrHCzmJfIYX_BpAz1qf0MfqeHfe3J3RRUb3uam3vSVdOWEDPy3AjtkEOHCXqX1Jx4hqxVH4Lmh3meG46lsP96VKXqERAelSfC370xGzi8BKy2w1UBMhAW71jr7kFRmEpAdVAh2QTWzZ1nscdUN-RYsK7G0rjlDZ_Lg2p8QlGJYOR_WTV31SUy8MoO1t1N3KXRRFjSKSL9JHg5C-u5L2aiQ048haQuf4h1kb8GG8hl4tGq&wd=&eqid=bc2385c300045f94000000046221d2ee",
            "https://image.baidu.com/search/detail?ct=503316480&z=undefined&tn=baiduimagedetail&ipn=d&word=%E5%A4%B4%E5%83%8F&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=undefined&hd=undefined&latest=undefined&copyright=undefined&cs=1099509886,2507091609&os=1760394763,1184408575&simid=1099509886,2507091609&pn=30&rn=1&di=7042744173476184065&ln=1972&fr=&fmq=1646384128422_R&fm=&ic=undefined&s=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&is=0,0&istype=0&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=0&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fup.enterdesk.com%252F2021%252Fedpic_source%252F07%252F09%252F47%252F070947ecb7af19ce4ed6f1c0cc11bb35_20.jpg%26refer%3Dhttp%253A%252F%252Fup.enterdesk.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1648976130%26t%3Db7170c7af92bde118fb26cb4e2587625&rpstart=0&rpnum=0&adpicid=0&nojc=undefined&dyTabStr=MCwzLDEsNSwyLDcsOCw2LDQsOQ%3D%3D",
            "https://image.baidu.com/search/detail?ct=503316480&z=undefined&tn=baiduimagedetail&ipn=d&word=%E5%A4%B4%E5%83%8F&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=undefined&hd=undefined&latest=undefined&copyright=undefined&cs=1099509886,2507091609&os=1760394763,1184408575&simid=1099509886,2507091609&pn=30&rn=1&di=7042744173476184065&ln=1972&fr=&fmq=1646384128422_R&fm=&ic=undefined&s=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&is=0,0&istype=0&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=0&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fup.enterdesk.com%252F2021%252Fedpic_source%252F07%252F09%252F47%252F070947ecb7af19ce4ed6f1c0cc11bb35_20.jpg%26refer%3Dhttp%253A%252F%252Fup.enterdesk.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1648976130%26t%3Db7170c7af92bde118fb26cb4e2587625&rpstart=0&rpnum=0&adpicid=0&nojc=undefined&dyTabStr=MCwzLDEsNSwyLDcsOCw2LDQsOQ%3D%3D",
            null
    };

    @Override
    public void randomSave(Integer count) {
        List<User> users = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < count; i++) {
            User user = new User();
            user.setMobileNo(getTel());
            user.setNickname(getChineseName());
            user.setSex(random.nextInt(3));
            user.setAvatar(avatars[random.nextInt(avatars.length)]);
            users.add(user);
        }
        saveBatch(users);
    }

    private String getTel() {
        int index = getNum(0, telFirst.length - 1);
        String first = telFirst[index];
        String second = String.valueOf(getNum(1, 888) + 10000).substring(1);
        String third = String.valueOf(getNum(1, 9100) + 10000).substring(1);
        return first + second + third;
    }

    private int getNum(int start, int end) {
        return (int) (Math.random() * (end - start + 1) + start);
    }

    private String getChineseName() {
        int index = getNum(0, firstName.length() - 1);
        String first = firstName.substring(index, index + 1);
        int sex = getNum(0, 1);
        String str = boy;
        int length = boy.length();
        if (sex == 0) {
            str = girl;
            length = girl.length();
//            name_sex = "女";
        } else {
//            name_sex = "男";
        }
        index = getNum(0, length - 1);
        String second = str.substring(index, index + 1);
        int hasThird = getNum(0, 1);
        String third = "";
        if (hasThird == 1) {
            index = getNum(0, length - 1);
            third = str.substring(index, index + 1);
        }
        return first + second + third;
    }
}
